package com.lingo.dingrobotutils.model.msgBuilder;

import com.dingtalk.api.request.OapiRobotSendRequest;
import com.lingo.dingrobotutils.model.component.DingFeedCardContent;

import java.util.ArrayList;
import java.util.List;

/**
 * @file: com.lingo.dingRobot.common.model.msgBuilder.DingFeedCardMsgBuilder
 * @Description: 封装 FeedCard 消息类型
 * @author: lingo
 * @version: v1.0
 * @date: 2020/3/23 12:10
 * @Company: www.xyb2b.com
 */

public class DingFeedCardMsgBuilder extends MyDingMsgBuilder {

    private final OapiRobotSendRequest.Feedcard feedcard = new OapiRobotSendRequest.Feedcard();


    public DingFeedCardMsgBuilder() {
        this.request.setMsgtype("feedCard");
        this.request.setFeedCard(feedcard);
    }


    public DingFeedCardMsgBuilder setFeedCardContent(List<DingFeedCardContent> contentList){
        if (contentList != null && !contentList.isEmpty()){
            List<OapiRobotSendRequest.Links> links = new ArrayList<>(contentList.size());
            contentList.forEach(content ->{
                OapiRobotSendRequest.Links tempLink = new OapiRobotSendRequest.Links();
                tempLink.setPicURL(content.getPicUrl());
                tempLink.setMessageURL(content.getMessageUrl());
                tempLink.setTitle(content.getTitle());
                links.add(tempLink);
            });
            feedcard.setLinks(links);
        }
        return this;
    }

    @Override
    public OapiRobotSendRequest build() {
        this.request.setFeedCard(feedcard);
        return request;
    }
}
